package com.lc.activiti.config;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.lc.activiti.sys.entity.SysUser;
import com.lc.activiti.utils.JwtUtil;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 权限拦截器
 * @author: 骆超
 * @date: 2021/5/21 11:11
 */
public class AuthInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle被调用");
        String token = request.getHeader("token");
        if (StrUtil.isEmpty(token)){
            response.setStatus(401);
            return false;
        }
        SysUser sysUser = JwtUtil.getUserByToken(token);
        System.out.println("token校验结果："+ ObjectUtil.isNotEmpty(sysUser));
        return ObjectUtil.isNotEmpty(sysUser);
    }

}
